/**
 * 
 */
package bpel.instructions;

import java.util.LinkedList;

import bpel.BPELProcess;

/**
 * @author Maurice & Topia
 * 
 */
public class BPELCase extends BPELInstruction {
	private BPELCondition condition;
	private LinkedList<BPELInstruction> instructions;

	public BPELCase() {
		instructions = new LinkedList<BPELInstruction>();
	}

	public void addInstruction(BPELInstruction instruction) {
		this.instructions.add(instruction);
	}

	public void setCondition(BPELCondition condition) {
		this.condition = condition;
	}

	@Override
	public String toString() {
		String caseStr = "";

		caseStr += "Case (" + condition.toString() + ") then{\n";

		for (BPELInstruction instruction : instructions) {
			caseStr += instruction.toString() + "\n";
		}

		caseStr += "}";

		return caseStr;
	}

	@Override
	public String execute(BPELProcess process) {
		if(condition.isTrue(process)){
			for(BPELInstruction i : instructions){
				i.execute(process);
			}
		}
		
		return null;
	}
}
